package ai.zixing.singleton;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 反射方式对单例的破坏
 */
public class Test_Reflect {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<Singleton_05> clazz = Singleton_05.class;
        Constructor<Singleton_05> constructor = clazz.getDeclaredConstructor();
        // 设置为可操作私有成员
        constructor.setAccessible(true);
        Singleton_05 instance01 = constructor.newInstance();
        Singleton_05 instance02 = constructor.newInstance();
        System.out.println(instance01);
        System.out.println(instance02);
    }
}
